package br.com.spread.svnutils;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import br.com.spread.svnutils.converters.PathConverter;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
import com.thoughtworks.xstream.annotations.XStreamConverter;

@XStreamAlias("logentry")
public class LogEntry {
	/**
	 * <pre>
	 * 	<logentry revision="2239">
	 * 		<author>jose.nascimento</author>
	 * 		<date>2014-03-25T18:57:25.211916Z</date>
	 * 		<paths>
	 * 			<path kind="file" action="M" prop-mods="false" text-mods="true">/branches/02-HMP/SIAAD_MNT_HMP_V101/03-Implementacao/Build/siaad.ear
	 * 			</path>
	 * 		</paths>
	 * 		<msg>scm-action SIAAD - Versao 10.0.1</msg>
	 * 	</logentry>
	 * </pre>
	 */

	/**
	 * 
	 */
	@XStreamAlias("revision")
	@XStreamAsAttribute
	Integer revision;

	/**
	 * 
	 */
	@XStreamAlias("author")
	String author;

	/**
	 * 
	 */
	@XStreamAlias("date")
	Date date;

	/**
	 * 
	 */
	@XStreamConverter(value=PathConverter.class, strings={"path"})
	List<Path> paths = new ArrayList<Path>();

	/**
	 * 
	 */
	@XStreamAlias("msg")
	String message;

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();

		Class<?> thisClass = null;
		try {
			thisClass = Class.forName(this.getClass().getName());

			Field[] aClassFields = thisClass.getDeclaredFields();
			sb.append(this.getClass().getSimpleName() + " [ ");
			for (Field f : aClassFields) {
				String fName = f.getName();
				sb.append(fName + ":" + f.get(this) + ", ");
			}
			sb.append("]");
		} catch (Exception e) {
			e.printStackTrace();
		}

		return sb.toString();
	}
}
